package com.stationbuilding.fragment.message;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.stationbuilding.R;
import com.stationbuilding.TestData;
import com.stationbuilding.activity.member.MemberDetailsActivity;
import com.stationbuilding.adapter.member.MemberListAdapter;
import com.stationbuilding.adapter.message.NoticeListAdapter;
import com.stationbuilding.adapter.message.TaskListAdapter;
import com.stationbuilding.bean.MemberBean;
import com.stationbuilding.bean.NoticeBean;
import com.stationbuilding.bean.TaskBean;
import com.stationbuilding.utils.PinyinComparator;
import com.stationbuilding.utils.PinyinUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class NoticeFragment extends Fragment {

    private View view;
    private ListView listView;
    private NoticeListAdapter noticeListAdapter;
    private List<NoticeBean> noticeList = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_notice, container, false);
        initViews();
        initEvents();
        return view;
    }

    private void initViews() {
        listView = (ListView) view.findViewById(R.id.notice_list);
        setAdapter();
    }

    private void setAdapter() {
        noticeListAdapter = new NoticeListAdapter(getActivity(), noticeList);
        listView.setAdapter(noticeListAdapter);
        // 数据加载
        loadNoticeData();
    }

    private void initEvents() {
        // ListView的点击事件
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(getActivity(), "position:" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void loadNoticeData() {
        noticeListAdapter.updateListView(TestData.getNoticeData());
    }
}
